package ${package};

import ${packageBase}.core.annotation.AuditAnnotation;
import ${packageBase}.core.dto.ImsResponse;
import ${packageBase}.core.model.PageInfo;
import ${packageBase}.core.vo.PageVO;
import ${packageBase}.${module}.biz.${className}Biz;
import ${packageBase}.${module}.dto.${className}DTO;
import ${packageBase}.${module}.vo.${className}SearchVO;
import ${packageBase}.${module}.vo.${className}VO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ${tableComment} 控制层
 *
 * @author motorfu
 * @email ffu@maxleap.com
 * @since ${date}
 */
@RestController
@RequestMapping("/${path}")
@Api(description = "${tableComment}")
public class ${className}Controller {

  private final ${className}Biz ${classNameSmall}Biz;

  @Autowired
  public ${className}Controller(${className}Biz ${classNameSmall}Biz) {
    this.${classNameSmall}Biz = ${classNameSmall}Biz;
  }

  @PostMapping(value = "/create",
      consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE},
      produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
  @ApiOperation(value = "创建${tableComment}")
  @AuditAnnotation(type = AuditType.CREATE)
  public ImsResponse<${className}DTO> create(@Valid @RequestBody ${className}VO ${classNameSmall}VO) {
    ${className}DTO dto = ${classNameSmall}Biz.create(${classNameSmall}VO);
    return ImsResponse.newBuilder(dto).build();
  }

  @PutMapping(value = "/modify",
      consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE},
      produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
  @ApiOperation(value = "修改${tableComment}")
  @AuditAnnotation(type = AuditType.MODIFY)
  public ImsResponse<${className}DTO> modify(@Valid @RequestBody ${className}VO ${classNameSmall}VO) {
    ${className}DTO dto = ${classNameSmall}Biz.modify(${classNameSmall}VO);
    return ImsResponse.newBuilder(dto).build();
    }

  @DeleteMapping(value = "/{id}", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
  @ApiOperation(value = "删除${tableComment}")
  @AuditAnnotation(type = AuditType.DELETE)
  public ImsResponse remove(@PathVariable Long id) {
    int result = ${classNameSmall}Biz.remove(id);
    return ImsResponse.newBuilder(result, "删除失败").build();
  }

  @GetMapping(value = "/{id}", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
  @ApiOperation(value = "根据id查找${tableComment}")
  public ImsResponse<${className}DTO> findById(@PathVariable Long id) {
    ${className}DTO dto = ${classNameSmall}Biz.find(id);
    return ImsResponse.newBuilder(dto).build();
  }

  @PostMapping(value = "/page",
      consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE},
      produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
  @ApiOperation(value = "${tableComment}分页")
  public ImsResponse<PageInfo<${className}DTO>> findPage(@Valid @RequestBody PageVO pageVO) {
    PageInfo<${className}DTO> pageinfo = ${classNameSmall}Biz.findPage(pageVO);
    return ImsResponse.newBuilder(pageinfo).build();
  }


  @PostMapping(value = "/search",
      consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE},
      produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
  @ApiOperation(value = "${tableComment}搜索，分页")
  public ImsResponse<PageInfo<${className}DTO>> search(@Valid @RequestBody ${className}SearchVO searchVO) {
    PageInfo<${className}DTO> pageInfo = ${classNameSmall}Biz.search(searchVO);
    return ImsResponse.newBuilder(pageInfo).build();
  }
}


